﻿from api.base_api import BaseApi


class ResourceApi(BaseApi):
    _yaml_path = "../datas/request_data/resource_api.yaml"

    def get_all_dept(self, env, token, corp_code, name):
        """
        获取医院所有的科室
        :param env:
        :param token:
        :param corp_code: 医院长编号
        :param name: 医院名字
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['corp_code'] = corp_code
        self._params['name'] = name
        data = self.yaml_read(self._yaml_path, 'get_all_dept')
        return self.send(data)

    def get_child_corp(self, env, token, corp_code, name, resource_id):
        """
        获取登录用户有权限该医院的父子院区
        :param resource_id:
        :param env:
        :param token:
        :param corp_code:
        :param name:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['corp_code'] = corp_code
        self._params['name'] = name
        self._params['id'] = resource_id
        data = self.yaml_read(self._yaml_path, 'get_child_corp')
        return self.send(data)

    def get_corp(self, env, token, corp_code, name, page_num, page_size):
        """
        获取医院所有科室
        :param page_size: 分页大小
        :param page_num: 页码
        :param env:
        :param token:
        :param corp_code: 医院长编号
        :param name: 医院名字
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['corp_code'] = corp_code
        self._params['name'] = name
        self._params['page_num'] = page_num
        self._params['page_size'] = page_size
        data = self.yaml_read(self._yaml_path, 'get_all_dept')
        return self.send(data)

    def get_list(self, env, token, sys_child_code, name):
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_child_code'] = sys_child_code
        self._params['name'] = name
        data = self.yaml_read(self._yaml_path, 'get_list')
        return self.send(data)

    def get_one(self, env, token, resource_id):
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['resource_id'] = resource_id
        data = self.yaml_read(self._yaml_path, 'get_one')
        return self.send(data)

    def delete(self, env, token, resource_id):
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['resource_id'] = resource_id
        data = self.yaml_read(self._yaml_path, 'delete')
        return self.send(data)

    def save(self, env, token, sys_child_code, name, res_code, res_url, resource_type, patient_id, res_priority,
             description):
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_child_code'] = sys_child_code
        self._params['name'] = name
        self._params['res_code'] = res_code
        self._params['res_url'] = res_url
        self._params['resource_type'] = resource_type
        self._params['patient_id'] = patient_id
        self._params['res_priority'] = res_priority
        self._params['description'] = description
        data = self.yaml_read(self._yaml_path, 'save')
        return self.send(data)

    def update(self, env, token, resource_id, name, res_url, res_priority, description):
        """
        修改
        :param env:
        :param token:
        :param resource_id: 模块id
        :param name: 模块名
        :param res_url: 模块地址
        :param res_priority:
        :param description:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['resource_id'] = resource_id
        self._params['name'] = name
        self._params['res_url'] = res_url
        self._params['res_priority'] = res_priority
        self._params['description'] = description
        data = self.yaml_read(self._yaml_path, 'update')
        return self.send(data)

    def get_all_resource(self, patient_id, sys_code):
        """
        获取子系统所有模块
        :param patient_id:传了就是查询二级tab ，不传就是初选系统的所有一级tab
        :param sys_code:子系统code .e.g:outpatient
        :return:
        """
        self._params['patient_id'] = patient_id
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'get_all_resource')
        return self.send(data)
